package test;

import java.util.Arrays;
import java.util.Scanner;
class PersonSortable implements Comparable <PersonSortable>{
	private String name ;
	private int age;
	public PersonSortable(String name,int age){
		this.name=name;
		this.age=age;
	}
	@Override
	public String toString() {
		return name+"-"+age;
	}
	
	@Override
	public int compareTo(PersonSortable per) {
		 int x=this.name.compareTo(per.name);
		 if(x!=0){
		 return x;
	}
		 else{
			 if(this.age>per.age)
				 return 1;
			 else if(this.age<per.age)
				 return -1;
			 else 
				 return 0;
		    }
		 }
	
}
 class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n=input.nextInt();
		String name;
		int age;
		PersonSortable []person=new PersonSortable[n];
		for(int i=0;i<n;i++){
			name=input.next();
			age=input.nextInt();
			person[i]=new PersonSortable(name,age);
		}
		
		Arrays.sort(person);
		for(int j=0;j<person.length;j++){
			System.out.println(person[j]);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}
}


